package com.lei.study.cds.unit2;

import org.mvel2.MVEL;
import org.mvel2.ParserContext;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 伍磊
 */
public class Test {

    private static final Map<String, Object> MAP = new HashMap<>();

    public static void main(String[] args) {
        // 初始化map数据
        MAP.put("REV", new BigDecimal("0.03"));
        MAP.put("REVF", new BigDecimal("0.02"));
        MAP.put("REVZ", new BigDecimal("0.01"));
        MAP.put("REVX", new BigDecimal("0.08"));

        ParserContext parserContext = MvelCalculateTools.initParse();

        // 编译
        Serializable compiled = MVEL.compileExpression
                ("STDEV(REV, REVF, REVZ, REVX)"
                        , parserContext);
        Object o = MVEL.executeExpression(compiled, MAP);
        System.out.println(o);
    }
}
